##############
## American Identity, Status Threat, and Backlash - Study 4, Public
##############

##############
## Load data
##############
rm(list=ls())
S4_D1 <- read.csv("Study 4 raw.csv", header = TRUE)
head(S4_D1)
nrow(S4_D1)
ncol(S4_D1)


##############
## Exclude participants who failed the attention check
##############
variable.names(S4_D1)
table(S4_D1$Att_Check2)
nrow(S4_D1)

## remove based on main attention check
S4_D2 <- S4_D1[which((S4_D1$Att_Check2) %in% c("meow","Meow","meow meow","meow =^.^=","meow!","meow or purr","Mhew :)","Mew","purr","No noise cat made","meows","meow!","Meow.","no","mew or meow, depending on how silly the cat is.",
                                               "Meow man","pur","MEOW","meow or miaow","meeow","meeowww","purrrrrrr","Meow meow","Meow!","moi","meows","meyow","none","MEOWW","Miya miya","meowwww","MEOW!","meow purrrrrrrrr",
                                               "meow!","mew","mewow","miau"," Meow!","this cat looks irritated, so it would be a growly kind of meow. Give him a treat.",
                                               "PURR", "purrrrr", "Purr","Mrrp?  Mrrrrrow.  mrrrrAAAAAA!","miow","miaow", " Miao or meow","Meow  Prrr Prrr","meow (or purrrrrr...) ","meow (or nya in japanese) ", "meo", "mea", "Meows",
                                               "MEOOOOOW", "Bark", "meow (or nya in japanese)","meow (or purrrrrr...)","Either a purr or a meow", "Meaw", "meow, hiss!","meow, meow, meeeeooww, mew, meow","meow and purr", "Meow Hiss",
                                               "meo","meoww","myaw","meeyow","Miao or meow","Meawww","meowwwwww","Meoww","meow/purr", "cat", "meow", "MEOW MEOW", "Meow Meow", " meow", "meoow",
                                               "MEOW MEOW", "Meow Meow","purr purr meow hissss","meow ","Mew, meow...","MEOW, purrrrrr!","	meooow!","meooow!","Meow","Meow, hiss","myau","Purr! :)","Meowww","Meow ","MEOOOWW","Meowwwew","Meow! ","Meowwww","Meow meow! =^.^=","Meow ",
                                               "meooooooooooooooow","Purrr","Meow. Or maybe that prrt noise cats make when they're saying hello.","meow.","meow/hiss","meow purr?","mey","Meow! Purr purr! Hiss!","Meow miau","Purring or meow","meow prrr","purrrr",
                                               "Meeeooooowwwww (im hungry in cat)","Meow hiss","Meow, meow, your magesty King Friday.","mrow","meow?","meoooooow meow","puurrrr","Meow or Purrrrr","moew","Meow!!","mewo","meowwwwwwwwwwwww","meeeeooooowwww","Meow or a purr depending","Meowwwwwwwwwww",
                                               "Meow…","Angry meow","me-ow","Meow, but it looks like its disappointed in me...","Mow mow","meow, meow","MEOW!!!!","Mew Meow Mrow Feed Me Meow","meoooowwwww","He looks like an angry cat, so it would be more of a MEROWRRRR",
                                               "meuw.","meow.","Moew","Meow or hiss or both depending on the cats mood every cat is different. Normally its just meow Meow feed me my can opener.","Meowwww.","meeeaw","beep beep","Meow.","Meow, purr, chirp, meow","Me-Ow","An unimpressed meow","meaw",
                                               "Meow purr","meaw","Puuuurrr","Ruff","Meow?","Meow or purr!","Meeeooooooowwwwrrrr!","purrr","Meow purrrr","meeeowwwww&lt;3","meow purr purr","MEEEEEEEEOOOOOOOOWWWWWWWW!","meow or nyahh",
                                               "Meow.","Meow and then knock something off the counter.","Meouw","Meow is what you wish it would say, but it doesn't look very compliant, to be honest","meow and/or hiss",
                                               "Meow/Purr","Meow, purr, chirp, meow","MEOW!!!! OH, BEHAVE!","Meooow","Miaow","Meow/Purr I was paying attention.","Meow or Hissing noise.","mrrrow","Meeowwwww")), ]
nrow(S4_D2)

## check those who failed
S4_D0 <- S4_D1[-which((S4_D1$Att_Check2) %in% c("meow","Meow","meow meow","meow =^.^=","meow!","meow or purr","Mhew :)","Mew","purr","No noise cat made","meows","meow!","Meow.","no","mew or meow, depending on how silly the cat is.",
                                                "Meow man","pur","MEOW","meow or miaow","meeow","meeowww","purrrrrrr","Meow meow","Meow!","moi","meows","meyow","none","MEOWW","Miya miya","meowwww","MEOW!","meow purrrrrrrrr",
                                                "meow!","mew","mewow","miau"," Meow!","this cat looks irritated, so it would be a growly kind of meow. Give him a treat.",
                                                "PURR", "purrrrr", "Purr","Mrrp?  Mrrrrrow.  mrrrrAAAAAA!","miow","miaow", " Miao or meow","Meow  Prrr Prrr","meow (or purrrrrr...) ","meow (or nya in japanese) ", "meo", "mea", "Meows",
                                                "MEOOOOOW", "Bark", "meow (or nya in japanese)","meow (or purrrrrr...)","Either a purr or a meow", "Meaw", "meow, hiss!","meow, meow, meeeeooww, mew, meow","meow and purr", "Meow Hiss",
                                                "meo","meoww","myaw","meeyow","Miao or meow","Meawww","meowwwwww","Meoww","meow/purr", "cat", "meow", "MEOW MEOW", "Meow Meow", " meow", "meoow",
                                                "MEOW MEOW", "Meow Meow","purr purr meow hissss","meow ","Mew, meow...","MEOW, purrrrrr!","	meooow!","meooow!","Meow","Meow, hiss","myau","Purr! :)","Meowww","Meow ","MEOOOWW","Meowwwew","Meow! ","Meowwww","Meow meow! =^.^=","Meow ",
                                                "meooooooooooooooow","Purrr","Meow. Or maybe that prrt noise cats make when they're saying hello.","meow.","meow/hiss","meow purr?","mey","Meow! Purr purr! Hiss!","Meow miau","Purring or meow","meow prrr","purrrr",
                                                "Meeeooooowwwww (im hungry in cat)","Meow hiss","Meow, meow, your magesty King Friday.","mrow","meow?","meoooooow meow","puurrrr","Meow or Purrrrr","moew","Meow!!","mewo","meowwwwwwwwwwwww","meeeeooooowwww","Meow or a purr depending","Meowwwwwwwwwww",
                                                "Meow…","Angry meow","me-ow","Meow, but it looks like its disappointed in me...","Mow mow","meow, meow","MEOW!!!!","Mew Meow Mrow Feed Me Meow","meoooowwwww","He looks like an angry cat, so it would be more of a MEROWRRRR",
                                                "meuw.","meow.","Moew","Meow or hiss or both depending on the cats mood every cat is different. Normally its just meow Meow feed me my can opener.","Meowwww.","meeeaw","beep beep","Meow.","Meow, purr, chirp, meow","Me-Ow","An unimpressed meow","meaw",
                                                "Meow purr","meaw","Puuuurrr","Ruff","Meow?","Meow or purr!","Meeeooooooowwwwrrrr!","purrr","Meow purrrr","meeeowwwww&lt;3","meow purr purr","MEEEEEEEEOOOOOOOOWWWWWWWW!","meow or nyahh",
                                                "Meow.","Meow and then knock something off the counter.","Meouw","Meow is what you wish it would say, but it doesn't look very compliant, to be honest","meow and/or hiss",
                                                "Meow/Purr","Meow, purr, chirp, meow","MEOW!!!! OH, BEHAVE!","Meooow","Miaow","Meow/Purr I was paying attention.","Meow or Hissing noise.","mrrrow","Meeowwwww")), ]
nrow(S4_D0)
#view(S4_D0$Att_Check2)
library(rstatix)
chisq_test(S4_D0$Att_Check2, S4_D0$Condition) ## inattentiveness does not vary by condition


## remove based on second attention check
table(S4_D2$White_ID_6)
S4_D3 <- subset(S4_D2, S4_D2$White_ID_6=="3") 
nrow(S4_D3)
chisq_test(S4_D2$White_ID_6, S4_D2$Condition) ## inattentiveness does not vary by condition


## Exclude all non-whites
table(S4_D3$Ethnicity)
S4_D3 <- subset(S4_D3, S4_D3$Ethnicity==1) 
nrow(S4_D3)


##############
## Demographic summary + balance tests
##############
variable.names(S4_D3)

table(S4_D3$Condition)
S4_D3$Condition [S4_D3$Condition == 1] <- "American Value"
S4_D3$Condition [S4_D3$Condition == 2] <- "American Hardship"
S4_D3$Condition [S4_D3$Condition == 3] <- "Control"

is.factor(S4_D3$Condition)

## Demographics
mean(S4_D3$Age, na.rm = TRUE)
sd(S4_D3$Age, na.rm = TRUE)
round(table(S4_D3$Ideology)/nrow(S4_D3)*100,2) ## percentage liberal
round(table(S4_D3$Gender)/nrow(S4_D3)*100,2) ## percentage female

## Balance tests
nrow(S4_D3)
table(S4_D3$Condition)
chisq.test(table(S4_D3$Condition, S4_D3$Age))
chisq.test(table(S4_D3$Condition, S4_D3$Gender))
chisq.test(table(S4_D3$Condition, S4_D3$Education))
chisq.test(table(S4_D3$Condition, S4_D3$Ideology))


##############
## Recode reverse-coded items and rename variables
##############
## recode second status threat item
library(car)
S4_D3$Status_Threat_2 = car::recode(S4_D3$Status_Threat_2, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")
S4_D3$Status_Threat_4 = car::recode(S4_D3$Status_Threat_4, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")

table(S4_D3$American_ID_4)
S4_D3$American_ID_1 = car::recode(S4_D3$American_ID_1, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S4_D3$American_ID_2 = car::recode(S4_D3$American_ID_2, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S4_D3$American_ID_3 = car::recode(S4_D3$American_ID_3, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")
S4_D3$American_ID_4 = car::recode(S4_D3$American_ID_4, "32=1; 33=2; 34=3; 35=4;36=5; 37=6; 38=7; else = NA")

## recode symbolic racism items
S4_D3$Sym_Racism__1 = car::recode(S4_D3$Sym_Racism__1, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")
S4_D3$Sym_Racism__2 = car::recode(S4_D3$Sym_Racism__2, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")
S4_D3$Sym_Racism__4 = car::recode(S4_D3$Sym_Racism__4, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else = NA")

## recode into opposition to racial policies
S4_D3$Rac_pol_1 = car::recode(S4_D3$Rac_pol_1, "1=5; 2=4; 3=3; 4=2; 5=1; else = NA")
S4_D3$Rac_pol_2 = car::recode(S4_D3$Rac_pol_2, "1=5; 2=4; 3=3; 4=2; 5=1; else = NA")

##############
## Factorial structure outgroup thermometers
##############
S4_D3_thermometers <- S4_D3[,c(49:53)]
head(S4_D3_thermometers)

## Visualize with scree plot
library(ggplot2)
library(psych)
fafitfree <- fa(S4_D3_thermometers,nfactors = 1, rotate = "promax", fm = "ml")
n_factors <- length(fafitfree$e.values)
scree     <- data.frame(
  Factor_n =  as.factor(1:n_factors), 
  Eigenvalue = fafitfree$e.values)
ggplot(scree, aes(x = Factor_n, y = Eigenvalue, group = 1)) + 
  geom_point() + geom_line() +
  xlab("Number of factors") +
  ylab("Initial eigenvalue") +
  labs( title = "Scree Plot", 
        subtitle = "(Based on the unreduced correlation matrix)")

##############
## Factorial structure National Pride
##############
S4_D3_pride <- S4_D3[,c(33:39)]
head(S4_D3_pride)

## Visualize with scree plot
library(ggplot2)
fafitfree <- fa(S4_D3_pride,nfactors = 1, rotate = "promax", fm = "ml")
n_factors <- length(fafitfree$e.values)
scree     <- data.frame(
  Factor_n =  as.factor(1:n_factors), 
  Eigenvalue = fafitfree$e.values)
ggplot(scree, aes(x = Factor_n, y = Eigenvalue, group = 1)) + 
  geom_point() + geom_line() +
  xlab("Number of factors") +
  ylab("Initial eigenvalue") +
  labs( title = "Scree Plot", 
        subtitle = "(Based on the unreduced correlation matrix)")


##############
## EFA Conceptions of nationhood
##############
S4_D3_nationhood <- S4_D3[,c(21:44)]
head(S4_D3_nationhood)

## Visualize with scree plot
library(ggplot2)
fafitfree <- fa(S4_D3_nationhood,nfactors = 1, rotate = "promax", fm = "ml")
n_factors <- length(fafitfree$e.values)
scree     <- data.frame(
  Factor_n =  as.factor(1:n_factors), 
  Eigenvalue = fafitfree$e.values)
ggplot(scree, aes(x = Factor_n, y = Eigenvalue, group = 1)) + 
  geom_point() + geom_line() +
  xlab("Number of factors") +
  ylab("Initial eigenvalue") +
  labs( title = "Scree Plot", 
        subtitle = "(Based on the unreduced correlation matrix)")


## KMO-test
KMO(S4_D3_nationhood) ## overall MSA = .93, so high to 1. Data thus suitable for FA

## Bartlett test
cortest.bartlett(S4_D3_nationhood) ## showing variables are correlated, H0 rejected. Data is not an identity matrix and FA is thus supported.

## scree-test
scree(S4_D3_nationhood, pc=FALSE) ## suggesting several factors

## parallel analysis
fa.parallel(S4_D3_nationhood, fa="fa") ## suggesting several factors

## EFA (factanal)
S4_D3_nationhood2 <- S4_D3_nationhood[complete.cases(S4_D3_nationhood), ] ## choose only complete cases
nrow(S4_D3_nationhood2)
S4_D3_nationhood3 <- factanal(S4_D3_nationhood2, 6, rotation="promax") ## replicates Huddy & Khatib
print(S4_D3_nationhood3, cutoff = .300)

load_S4_D3_nationhood3 <- S4_D3_nationhood3$loadings[,1:6] ## plot S4_D3_nationhood3
plot(load_S4_D3_nationhood3,type="n") # set up plot
text(load_S4_D3_nationhood3,labels=names(S4_D3_nationhood2),cex=.7)

loads_S4_D3_nationhood3 <- S4_D3_nationhood3$loadings ## visualize factor model
fa.diagram(loads_S4_D3_nationhood3)



##############
## CFA Conceptions of nationhood
##############
library(lavaan)
CFA_Conceptions_S4 <- '
## Direct effect condition on outcomes (path c) 
AM_ID =~ American_ID_1 + American_ID_2 + American_ID_3 + American_ID_4
White_ID =~ White_ID_1 + White_ID_2 + White_ID_3 + White_ID_4 + White_ID_5
Patr =~ Patriotism_1 + Patriotism_2
Natio =~ Nationalism_1 + Nationalism_2
Pride =~ Pride_1 + Pride_2 + Pride_3 + Pride_4 + Pride_5 + Pride_6 + Pride_7
Cons_Pat =~ Constr_Pat_1 + Constr_Pat_2 + Constr_Pat_3 + Constr_Pat_4

AM_ID ~~ White_ID
AM_ID ~~ Patr
AM_ID ~~ Natio
AM_ID ~~ Pride
AM_ID ~~ Cons_Pat
White_ID ~~ Patr
White_ID ~~ Natio
White_ID ~~ Pride
White_ID ~~ Cons_Pat
Patr ~~ Natio
Patr ~~ Pride
Patr ~~ Cons_Pat
Natio ~~ Pride
Natio ~~ Cons_Pat
Pride ~~ Cons_Pat

## modindices
Pride_3 ~~Pride_6
American_ID_4 ~~ White_ID_5
Pride_1 ~~ Pride_4
Pride_1 ~~ Pride_2

'

CFA_Conceptions_S4_fit <- cfa(CFA_Conceptions_S4, se = "bootstrap", bootstrap = 100, data = S4_D3)
summary(CFA_Conceptions_S4_fit, fit.measures = TRUE, rsquare = TRUE)
modindices(CFA_Conceptions_S4_fit, max = 30, sort = TRUE)




##############
## Reliabilities
##############
colnames(S4_D3)
which( colnames(S4_D3)=="Pride_1" )

psych::alpha(select(S4_D3, 16:20)) ## Status threat
psych::alpha(select(S4_D3, 21:24)) ## American identity
psych::alpha(select(S4_D3, 29:30)) ## Symbolic patriotism
psych::alpha(select(S4_D3, 25:28)) ## Constructive patriotism
psych::alpha(select(S4_D3, 31:32)) ## Nationalism
psych::alpha(select(S4_D3, 33:39)) ## National pride
psych::alpha(select(S4_D3, 40:44)) ## white identity

psych::alpha(select(S4_D3, 49:53)) ## Outgroup thermometers
psych::alpha(select(S4_D3, 55:58)) ## Symbolic racism
psych::alpha(select(S4_D3, 59:62)) ## Racial policies


##############
## Mean Scales
##############
S4_D3$mean_Status_Threat <- (S4_D3$Status_Threat_1 + S4_D3$Status_Threat_2 + S4_D3$Status_Threat_3 + S4_D3$Status_Threat_4 + S4_D3$Status_Threat_5)/5
S4_D3$mean_American_Identity <- (S4_D3$American_ID_1 + S4_D3$American_ID_2 + S4_D3$American_ID_3 + S4_D3$American_ID_4)/4
S4_D3$mean_White_Identity <- (S4_D3$White_ID_1 + S4_D3$White_ID_2 + S4_D3$White_ID_3 + S4_D3$White_ID_4 + S4_D3$White_ID_5)/5
S4_D3$mean_Symbolic_Patriotism <- (S4_D3$Patriotism_1 + S4_D3$Patriotism_2)/2
S4_D3$mean_Constructive_Patriotism <- (S4_D3$Constr_Pat_1 + S4_D3$Constr_Pat_2 + S4_D3$Constr_Pat_3 + S4_D3$Constr_Pat_4)/4
S4_D3$mean_Nationalism <- (S4_D3$Nationalism_1 + S4_D3$Nationalism_2)/2
S4_D3$mean_National_Pride <- (S4_D3$Pride_1 + S4_D3$Pride_2 + S4_D3$Pride_3 + S4_D3$Pride_4 + S4_D3$Pride_5 + S4_D3$Pride_6 + S4_D3$Pride_7)/7
S4_D3$mean_Outgroup_Warmth <- (S4_D3$Thermometers_6 + S4_D3$Thermometers_7 + S4_D3$Thermometers_8 + S4_D3$Thermometers_9 + S4_D3$Thermometers_10)/5
S4_D3$mean_Symbolic_Racism <- (S4_D3$Sym_Racism__1 + S4_D3$Sym_Racism__2 + S4_D3$Sym_Racism__3 + S4_D3$Sym_Racism__4)/4
S4_D3$mean_Racial_Policies <- (S4_D3$Rac_pol_1 + S4_D3$Rac_pol_2 + S4_D3$Rac_pol_3 + S4_D3$Rac_pol_4)/4


##############
## Rescaling
##############
S4_D3$mean_Status_Threat_scaled <- (S4_D3$mean_Status_Threat - min(S4_D3$mean_Status_Threat, na.rm = TRUE)) / (max(S4_D3$mean_Status_Threat, na.rm = TRUE) - min(S4_D3$mean_Status_Threat, na.rm = TRUE))
S4_D3$mean_American_Identity_scaled <- (S4_D3$mean_American_Identity - min(S4_D3$mean_American_Identity, na.rm = TRUE)) / (max(S4_D3$mean_American_Identity, na.rm = TRUE) - min(S4_D3$mean_American_Identity, na.rm = TRUE))
S4_D3$mean_White_Identity_scaled <- (S4_D3$mean_White_Identity - min(S4_D3$mean_White_Identity, na.rm = TRUE)) / (max(S4_D3$mean_White_Identity, na.rm = TRUE) - min(S4_D3$mean_White_Identity, na.rm = TRUE))
S4_D3$mean_Symbolic_Patriotism_scaled <- (S4_D3$mean_Symbolic_Patriotism - min(S4_D3$mean_Symbolic_Patriotism, na.rm = TRUE)) / (max(S4_D3$mean_Symbolic_Patriotism, na.rm = TRUE) - min(S4_D3$mean_Symbolic_Patriotism, na.rm = TRUE))
S4_D3$mean_Constructive_Patriotism_scaled <- (S4_D3$mean_Constructive_Patriotism - min(S4_D3$mean_Constructive_Patriotism, na.rm = TRUE)) / (max(S4_D3$mean_Constructive_Patriotism, na.rm = TRUE) - min(S4_D3$mean_Constructive_Patriotism, na.rm = TRUE))
S4_D3$mean_Nationalism_scaled <- (S4_D3$mean_Nationalism - min(S4_D3$mean_Nationalism, na.rm = TRUE)) / (max(S4_D3$mean_Nationalism, na.rm = TRUE) - min(S4_D3$mean_Nationalism, na.rm = TRUE))
S4_D3$mean_National_Pride_scaled <- (S4_D3$mean_National_Pride - min(S4_D3$mean_National_Pride, na.rm = TRUE)) / (max(S4_D3$mean_National_Pride, na.rm = TRUE) - min(S4_D3$mean_National_Pride, na.rm = TRUE))
S4_D3$mean_Outgroup_Warmth_scaled <- (S4_D3$mean_Outgroup_Warmth - min(S4_D3$mean_Outgroup_Warmth, na.rm = TRUE)) / (max(S4_D3$mean_Outgroup_Warmth, na.rm = TRUE) - min(S4_D3$mean_Outgroup_Warmth, na.rm = TRUE))
S4_D3$IOS_scaled <- (S4_D3$IOS - min(S4_D3$IOS, na.rm = TRUE)) / (max(S4_D3$IOS, na.rm = TRUE) - min(S4_D3$IOS, na.rm = TRUE))
S4_D3$mean_Symbolic_Racism_scaled <- (S4_D3$mean_Symbolic_Racism - min(S4_D3$mean_Symbolic_Racism, na.rm = TRUE)) / (max(S4_D3$mean_Symbolic_Racism, na.rm = TRUE) - min(S4_D3$mean_Symbolic_Racism, na.rm = TRUE))
S4_D3$Dems_scaled <- (S4_D3$Thermometers_3 - min(S4_D3$Thermometers_3, na.rm = TRUE)) / (max(S4_D3$Thermometers_3, na.rm = TRUE) - min(S4_D3$Thermometers_3, na.rm = TRUE))
S4_D3$Reps_scaled <- (S4_D3$Thermometers_4 - min(S4_D3$Thermometers_4, na.rm = TRUE)) / (max(S4_D3$Thermometers_4, na.rm = TRUE) - min(S4_D3$Thermometers_4, na.rm = TRUE))
S4_D3$mean_Racial_Policies_scaled <- (S4_D3$mean_Racial_Policies - min(S4_D3$mean_Racial_Policies, na.rm = TRUE)) / (max(S4_D3$mean_Racial_Policies, na.rm = TRUE) - min(S4_D3$mean_Racial_Policies, na.rm = TRUE))

S4_D3$Blacks_scaled <- (S4_D3$Thermometers_6 - min(S4_D3$Thermometers_6, na.rm = TRUE)) / (max(S4_D3$Thermometers_6, na.rm = TRUE) - min(S4_D3$Thermometers_6, na.rm = TRUE))
S4_D3$Asians_scaled <- (S4_D3$Thermometers_7 - min(S4_D3$Thermometers_7, na.rm = TRUE)) / (max(S4_D3$Thermometers_7, na.rm = TRUE) - min(S4_D3$Thermometers_7, na.rm = TRUE))
S4_D3$Hispanics_scaled <- (S4_D3$Thermometers_8 - min(S4_D3$Thermometers_8, na.rm = TRUE)) / (max(S4_D3$Thermometers_8, na.rm = TRUE) - min(S4_D3$Thermometers_8, na.rm = TRUE))
S4_D3$Illegal_scaled <- (S4_D3$Thermometers_9 - min(S4_D3$Thermometers_9, na.rm = TRUE)) / (max(S4_D3$Thermometers_9, na.rm = TRUE) - min(S4_D3$Thermometers_9, na.rm = TRUE))
S4_D3$Legal_scaled <- (S4_D3$Thermometers_10 - min(S4_D3$Thermometers_10, na.rm = TRUE)) / (max(S4_D3$Thermometers_10, na.rm = TRUE) - min(S4_D3$Thermometers_10, na.rm = TRUE))


S4_D3$Ideology_scaled <- (S4_D3$Ideology - min(S4_D3$Ideology, na.rm = TRUE)) / (max(S4_D3$Ideology, na.rm = TRUE) - min(S4_D3$Ideology, na.rm = TRUE))


##############
## Correlations Conceptions of nationhood
##############
library(corrplot)
library(dplyr)
library(apaTables)

correlations_constructs_S4 <- as.data.frame(cbind(S4_D3$mean_American_Identity_scaled, S4_D3$mean_White_Identity_scaled,S4_D3$mean_Symbolic_Patriotism_scaled, S4_D3$mean_Constructive_Patriotism_scaled,S4_D3$mean_Nationalism_scaled,S4_D3$mean_National_Pride_scaled,
                                               S4_D3$mean_Status_Threat_scaled))
correlations_constructs_S4_2 <- correlations_constructs_S4 %>% 
  rename(
    "American ID" = V1,
    "White ID" = V2,    
    "Symbolic patriotism" = V3,
    "Constructive patriotism" = V4,
    "Nationalism" = V5,
    "National pride" = V6,
    "Status Threat" = V7)
str(correlations_constructs_S4_2)

## Correlation Table
apa.cor.table(correlations_constructs_S4_2, table.number = 2, show.sig.stars = TRUE, show.conf.interval = FALSE, filename = "construct_correlations.doc")
cortable_S4 <- apa.cor.table(correlations_constructs_S4_2, table.number = 2, show.sig.stars = TRUE, show.conf.interval = FALSE, filename = "construct_correlations.doc")

## Significance test of correlations
correlations_constructs_S4_sig <- cor.mtest(correlations_constructs_S4_2)

## Correlogram 
construct_corr_S4 <- cor(correlations_constructs_S4_2, use = "complete.obs")
head(round(construct_corr_S4,2))

corrplot(construct_corr_S4, method="color", addCoef.col = "black", p.mat = correlations_constructs_S4_sig$p, sig.level = 0.001, type = "lower", insig = "blank", diag = TRUE,
         title = "",
         tl.cex = 0.5, number.cex = 0.4, cl.align.text = "l", tl.pos = "ld", tl.col="black", tl.offset = 3)
ggsave("Correlations_S4.jpeg", scale = 1, dpi="retina", dev='jpeg', height=5, width=5, units="in")


##############
## Descriptives
##############
table(S4_D3$Condition)
S4_D3$Condition <- factor(S4_D3$Condition, levels = c("American Hardship", "American Value","Control"))
S4_D3$Condition_num <- as.numeric(as.factor(S4_D3$Condition))
table(S4_D3$Condition_num)

S4_t1 <- t(round(S4_D3 %>%
                   group_by(Condition_num) %>%
                   summarise_at(vars(c(mean_Status_Threat_scaled, 
                                       mean_American_Identity_scaled, mean_White_Identity_scaled,mean_Symbolic_Patriotism_scaled,mean_Constructive_Patriotism_scaled, mean_Nationalism_scaled,mean_National_Pride_scaled,
                                       mean_Outgroup_Warmth_scaled, IOS_scaled,mean_Symbolic_Racism_scaled,
                                       Dems_scaled,Reps_scaled,mean_Racial_Policies_scaled,
                                       Blacks_scaled,Asians_scaled,Hispanics_scaled,Illegal_scaled,Legal_scaled)), list(mean = mean, sd = sd), na.rm = TRUE),2))
write.table(S4_t1, file = "S4_t1.txt", sep = ",", quote = FALSE, row.names = F)



##############
## Simple mean differences (descriptive, not used for hypothesis testing)
##############
## Status threat
S4_aov1 <- aov(mean_Status_Threat_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov1)
S4_reg1 <- lm(mean_Status_Threat_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg1)

library(effectsize)
cohens_f(S4_reg1, partial = FALSE)

## American identity
S4_aov2 <- aov(mean_American_Identity_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov2)
S4_reg2 <- lm(mean_American_Identity_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg2)
cohens_f(S4_reg2, partial = FALSE)
0.52/2 ## Cohen's d = 2f, i.e., f/2 = Cohen's d. 

## White identity
S4_aov3 <- aov(mean_White_Identity_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov3)
S4_reg3 <- lm(mean_White_Identity_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg3)
cohens_f(S4_reg3, partial = FALSE)


## Symbolic patriotism
S4_aov4 <- aov(mean_Symbolic_Patriotism_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov4)
S4_reg4 <- lm(mean_Symbolic_Patriotism_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg4)
cohens_f(S4_reg4, partial = FALSE)

## Symbolic patriotism
S5_aov4 <- aov(mean_Constructive_Patriotism_scaled ~ factor(Condition), data = S4_D3)
summary(S5_aov4)
S5_reg4 <- lm(mean_Constructive_Patriotism_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S5_reg4)
cohens_f(S5_reg4, partial = FALSE)

## Nationalism
S6_aov5 <- aov(mean_Nationalism_scaled ~ factor(Condition), data = S4_D3)
summary(S6_aov5)
S6_reg5 <- lm(mean_Nationalism_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S6_reg5)
cohens_f(S6_reg5, partial = FALSE)


## National pride
S7_aov6 <- aov(mean_National_Pride_scaled ~ factor(Condition), data = S4_D3)
summary(S7_aov6)
S7_reg6 <- lm(mean_National_Pride_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S7_reg6)
cohens_f(S7_reg6, partial = FALSE)


## Outgroup warmth
S8_aov7 <- aov(mean_Outgroup_Warmth_scaled ~ factor(Condition), data = S4_D3)
summary(S8_aov7)
S8_aov7 <- lm(mean_Outgroup_Warmth_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S8_aov7)

## Inclusiveness
S4_aov9 <- aov(IOS_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov9)
S4_aov9 <- lm(IOS_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_aov9)

## Americanness
S4_aov10 <- aov(mean_Symbolic_Racism_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov10)
S4_reg10 <- lm(mean_Symbolic_Racism_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg10)

## Democrat warmth
S4_aov11 <- aov(Dems_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov11)
S4_reg11 <- lm(Dems_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg11)

## Republican warmth
S4_aov12 <- aov(Reps_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov12)
S4_reg12 <- lm(Reps_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg12)

## Opposition racial policies
S4_aov13 <- aov(mean_Racial_Policies_scaled ~ factor(Condition), data = S4_D3)
summary(S4_aov13)
S4_reg13 <- lm(mean_Racial_Policies_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_reg13)

## Separate outgroups: thermometers
S4_aov14a <- aov(Blacks_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
S4_aov14b <- aov(Asians_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
S4_aov14c <- aov(Hispanics_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
S4_aov14d <- aov(Illegal_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
S4_aov14e <- aov(Legal_scaled ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_aov14a)
summary(S4_aov14b)
summary(S4_aov14c)
summary(S4_aov14d)
summary(S4_aov14e)



##############
## Moderating ideology
##############
S4_aov1_ideo <- aov(mean_Status_Threat_scaled ~ factor(Condition)*Ideology_scaled, data = S4_D3)
summary(S4_aov1_ideo)
S4_reg1_ideo <- lm(mean_Status_Threat_scaled ~ factor(Condition)*Ideology_scaled, data = S4_D3)
summary(S4_reg1_ideo)

S4_aov2_ideo <- aov(mean_American_Identity_scaled ~ factor(Condition)*Ideology_scaled, data = S4_D3)
summary(S4_aov2_ideo)
S4_reg2a_ideo <- lm(mean_American_Identity_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
S4_reg2b_ideo <- lm(mean_American_Identity_scaled ~ factor(Condition)*Ideology_scaled, data = S4_D3)
summary(S4_reg2a_ideo)
summary(S4_reg2b_ideo)
library(interactions) 
interact_plot(S4_reg2b_ideo, pred = Ideology_scaled, modx = Condition)

S4_aov3_ideo <- aov(mean_Status_Threat_scaled ~ mean_American_Identity_scaled*Ideology_scaled, data = S4_D3)
summary(S4_aov3_ideo)
S4_reg3_ideo <- lm(mean_Status_Threat_scaled ~ mean_American_Identity_scaled*Ideology_scaled, data = S4_D3)
summary(S4_reg3_ideo)

S4_reg4_ideo <- lm(mean_White_Identity_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
S4_reg5_ideo <- lm(mean_Symbolic_Patriotism_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
S4_reg6_ideo <- lm(mean_Constructive_Patriotism_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
S4_reg7_ideo <- lm(mean_Nationalism_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
S4_reg8_ideo <- lm(mean_National_Pride_scaled ~ relevel(factor(Condition), ref = 3)*Ideology_scaled, data = S4_D3)
summary(S4_reg4_ideo)
summary(S4_reg5_ideo)
summary(S4_reg6_ideo)
summary(S4_reg7_ideo)
summary(S4_reg8_ideo)

##############
## Mediation through status threat
##############
library(lavaan)

## Dummy-code conditions
table(S4_D3$Condition)
S4_D3$Condition_Control <- ifelse(S4_D3$Condition == "Control", 1, 0)
S4_D3$Condition_Value <- ifelse (S4_D3$Condition =="American Value", 1, 0)
S4_D3$Condition_Hard <- ifelse(S4_D3$Condition == "American Hardship", 1, 0)

## Comparison value and hardship vs. control
## insert DV as needed
S4_D3_simple_mediation <- '
## Direct effect condition on outcomes (path c) 
IOS_scaled ~ c1*Condition_Value + c2*Condition_Hard

## Indirect effect 1: condition on reported American identity (path a)
mean_Status_Threat_scaled ~ a1*Condition_Value + a2*Condition_Hard

## Indirect effect 2: reported American identity on status threat + controls (path b)
IOS_scaled ~ b1*mean_Status_Threat_scaled

## direct effect
direct_Value := c1
direct_Hard := c2

## indirect effect (a*b): Sobel test (Delta method)
indirect_Value := a1*b1
indirect_Hard := a2*b1

## total effect
total_Value := c1 + (a1*b1)
total_Hard := c2 + (a2*b1)
'

## comparing value and hardship vs. control
S4_D3_simple_mediation_Outgroup_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
S4_D3_simple_mediation_Inclusiveness_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
S4_D3_simple_mediation_Racism_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
S4_D3_simple_mediation_Democrats_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
S4_D3_simple_mediation_Republicans_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
S4_D3_simple_mediation_Policies_fit <- sem(S4_D3_simple_mediation, se = "bootstrap", bootstrap = 5000, data = S4_D3)
summary(S4_D3_simple_mediation_Outgroup_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S4_D3_simple_mediation_Inclusiveness_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S4_D3_simple_mediation_Racism_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S4_D3_simple_mediation_Democrats_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S4_D3_simple_mediation_Republicans_fit, fit.measures = TRUE, rsquare = TRUE)
summary(S4_D3_simple_mediation_Policies_fit, fit.measures = TRUE, rsquare = TRUE)

##############
## Word cloud
##############
library(wordcloud)
library(RColorBrewer)
library(wordcloud2)
library(tm)

colnames(S4_D3)
## Word Cloud: Values
S4_D3$Values_all <- paste(S4_D3$American_Value_Prime_1, S4_D3$American_Value_Prime_2, S4_D3$American_Value_Prime_3, sep = ", ")
Values_all_open_text <- S4_D3$Values_all
Values_all_open_text_docs <- Corpus(VectorSource(Values_all_open_text)) ## create a corpus
Values_all_open_text_docs <- Values_all_open_text_docs %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
Values_all_open_text_docs <- tm_map(Values_all_open_text_docs, content_transformer(tolower))
Values_all_open_text_docs <- tm_map(Values_all_open_text_docs, removeWords, stopwords("english"))
Values_all_open_text_docs_matrix <- TermDocumentMatrix(Values_all_open_text_docs) 
Values_all_open_text_docs_matrix2 <- as.matrix(Values_all_open_text_docs_matrix) 
Values_all_words <- sort(rowSums(Values_all_open_text_docs_matrix2),decreasing=TRUE) 
head(Values_all_words)
df_Values_all_words <- data.frame(word = names(Values_all_words),freq=Values_all_words)
df_Values_all_words [ which(df_Values_all_words$freq>1), ]
values_cloud <- wordcloud2(data=df_Values_all_words, size=1.6, color='random-dark')

## Word Cloud: Human Hardships
S4_D3$AmHardship_all <- paste(S4_D3$American_Hardship_Pr_1, S4_D3$American_Hardship_Pr_2, S4_D3$American_Hardship_Pr_3, sep = ", ")
AmHardship_all_open_text <- S4_D3$AmHardship_all
AmHardship_all_open_text_docs <- Corpus(VectorSource(AmHardship_all_open_text)) ## create a corpus
AmHardship_all_open_text_docs <- AmHardship_all_open_text_docs %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
AmHardship_all_open_text_docs <- tm_map(AmHardship_all_open_text_docs, content_transformer(tolower))
AmHardship_all_open_text_docs <- tm_map(AmHardship_all_open_text_docs, removeWords, stopwords("english"))
AmHardship_all_open_text_docs_matrix <- TermDocumentMatrix(AmHardship_all_open_text_docs) 
AmHardship_all_open_text_docs_matrix2 <- as.matrix(AmHardship_all_open_text_docs_matrix) 
AmHardship_all_words <- sort(rowSums(AmHardship_all_open_text_docs_matrix2),decreasing=TRUE) 
head(AmHardship_all_words)
df_AmHardship_all_words <- data.frame(word = names(AmHardship_all_words),freq=AmHardship_all_words)
df_AmHardship_all_words [ which(df_AmHardship_all_words$freq>30), ]
AmHardship_cloud <- wordcloud2(data=df_AmHardship_all_words, size=1.6, color='random-dark')

## Word Cloud: Control
S4_D3$Control_all <- paste(S4_D3$Control_Task_1, S4_D3$Control_Task_2, S4_D3$Control_Task_3, sep = ", ")
Control_all_open_text <- S4_D3$Control_all
Control_all_open_text_docs <- Corpus(VectorSource(Control_all_open_text)) ## create a corpus
Control_all_open_text_docs <- Control_all_open_text_docs %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
Control_all_open_text_docs <- tm_map(Control_all_open_text_docs, content_transformer(tolower))
Control_all_open_text_docs <- tm_map(Control_all_open_text_docs, removeWords, stopwords("english"))
Control_all_open_text_docs_matrix <- TermDocumentMatrix(Control_all_open_text_docs) 
Control_all_open_text_docs_matrix2 <- as.matrix(Control_all_open_text_docs_matrix) 
Control_all_words <- sort(rowSums(Control_all_open_text_docs_matrix2),decreasing=TRUE) 
head(Control_all_words)
df_Control_all_words <- data.frame(word = names(Control_all_words),freq=Control_all_words)
df_Control_all_words [ which(df_Control_all_words$freq>30), ]
Control_cloud <- wordcloud2(data=df_Control_all_words, size=1.6, color='random-dark')

##############
## What groups did people think about?
##############
colnames(S4_D3)

## Qualitative open-text
## Count: Values
ID_Values <- S4_D3$Identity_Value_1
ID_Values <- Corpus(VectorSource(ID_Values)) ## create a corpus
ID_Values <- ID_Values %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
ID_Values <- tm_map(ID_Values, content_transformer(tolower))
ID_Values <- tm_map(ID_Values, removeWords, stopwords("english"))
ID_Values <- TermDocumentMatrix(ID_Values) 
ID_Values <- as.matrix(ID_Values) 
ID_Values_words <- sort(rowSums(ID_Values),decreasing=TRUE) 
table(ID_Values_words)

## Count: Hardships
ID_Hardships <- S4_D3$Identity_Hardship_1
ID_Hardships <- Corpus(VectorSource(ID_Hardships)) ## create a corpus
ID_Hardships <- ID_Hardships %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
ID_Hardships <- tm_map(ID_Hardships, content_transformer(tolower))
ID_Hardships <- tm_map(ID_Hardships, removeWords, stopwords("english"))
ID_Hardships <- TermDocumentMatrix(ID_Hardships) 
ID_Hardships <- as.matrix(ID_Hardships) 
ID_Hardships_words <- sort(rowSums(ID_Hardships),decreasing=TRUE) 
table(ID_Hardships_words)

## Count: Control
ID_Control <- S4_D3$Identity_Control_1
ID_Control <- Corpus(VectorSource(ID_Control)) ## create a corpus
ID_Control <- ID_Control %>%
  tm_map(removeNumbers) %>%
  tm_map(removePunctuation) %>%
  tm_map(stripWhitespace)
ID_Control <- tm_map(ID_Control, content_transformer(tolower))
ID_Control <- tm_map(ID_Control, removeWords, stopwords("english"))
ID_Control <- TermDocumentMatrix(ID_Control) 
ID_Control <- as.matrix(ID_Control) 
ID_Control_words <- sort(rowSums(ID_Control),decreasing=TRUE) 
table(ID_Control_words)

## Quantitative multiple choice
data4 <- S4_D3 %>% rename("People_like_me" = "Identity_all1_1","Americans" = "Identity_all1_2","People_in_need" = "Identity_all1_4",
                          "No_group_at_all" = "Identity_all1_5","White_people" = "Identity_all1_6","People_of_Color" = "Identity_all1_7",
                          "Humans_in_general" = "Identity_all1_8","Conservatives" = "Identity_all1_9","Liberals" = "Identity_all1_10",
                          "Friends_and_family" = "Identity_all1_11","People_with_similar_food_preferences" = "Identity_all1_13","Workers" = "Identity_all1_14",
                          "I_thought_about_myself" = "Identity_all1_15","Other_groups" = "Identity_all1_16")

colnames(S4_D3)
table(S4_D3$Condition)
u <- t(round(data4 %>%
               group_by(Condition_num) %>%
               summarise_at(vars(c(People_like_me,Americans,People_in_need,No_group_at_all,White_people,People_of_Color,Humans_in_general,Conservatives,Liberals,
                                   Friends_and_family,People_with_similar_food_preferences,Workers,I_thought_about_myself,Other_groups)), list(sum = sum), na.rm = TRUE),2))

round(u[,2]/460*100,2) ## Percentages Value
round(u[,1]/457*100,2) ## Percentages Hardship
round(u[,3]/477*100,2) ## Percentages Control


data5 <- subset(S4_D3[,c(66:79,91)])
head(data5)
data5[is.na(data5)] <- 0
table(data5$People_like_me)

group1 <- lm(Identity_all1_1 ~ relevel(factor(Condition), ref = 1), data = (data5))
group2 <- lm(Identity_all1_2 ~ relevel(factor(Condition), ref = 1), data = (data5))
group3 <- lm(Identity_all1_4 ~ relevel(factor(Condition), ref = 1), data = (data5))
group4 <- lm(Identity_all1_5 ~ relevel(factor(Condition), ref = 1), data = (data5))
group5 <- lm(Identity_all1_6 ~ relevel(factor(Condition), ref = 1), data = (data5))
group6 <- lm(Identity_all1_7 ~ relevel(factor(Condition), ref = 1), data = (data5))
group7 <- lm(Identity_all1_8 ~ relevel(factor(Condition), ref = 1), data = (data5))
group8 <- lm(Identity_all1_9 ~ relevel(factor(Condition), ref = 1), data = (data5))
group9 <- lm(Identity_all1_10 ~ relevel(factor(Condition), ref = 1), data = (data5))
group10 <- lm(Identity_all1_11 ~ relevel(factor(Condition), ref = 1), data = (data5))
group11 <- lm(Identity_all1_13 ~ relevel(factor(Condition), ref = 1), data = (data5))
group12 <- lm(Identity_all1_14 ~ relevel(factor(Condition), ref = 1), data = (data5))
group13 <- lm(Identity_all1_15 ~ relevel(factor(Condition), ref = 1), data = (data5))
group14 <- lm(Identity_all1_16 ~ relevel(factor(Condition), ref = 1), data = (data5))
summary(group1)
summary(group2)
summary(group3)
summary(group4)
summary(group5)
summary(group6)
summary(group7)
summary(group8)
summary(group9)
summary(group10)
summary(group11)
summary(group12)
summary(group13)
summary(group14)







##############
## Exploratory: Effect on affective polarization
##############
## Compute AP-score
S4_D3$AP_score <- abs((S4_D3$Thermometers_3 - S4_D3$Thermometers_4))
head(S4_D3[1:6,c("Thermometers_3","Thermometers_4","AP_score")])

## Run regressions
S4_aovAP <- aov(AP_score ~ factor(Condition), data = S4_D3)
summary(S4_aovAP)
S4_regAP <- lm(AP_score ~ relevel(factor(Condition), ref = 3), data = S4_D3)
summary(S4_regAP)
cohens_f(S4_regAP, partial = FALSE)

##############
## End of the syntax.




